﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace TicketManagement
{
    public partial class 注册景区 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int username = int.Parse(this.username.Text);
            string password = this.password.Text;
            int identity = 4;

            int sp_id = int.Parse(this.sp_id.Text);
            string sp_name = this.sp_name.Text;
            long sp_tel = long.Parse(this.sp_tel.Text);
            string sp_address = this.sp_address.Text;
            int sp_level = 0;
            if (RadioButtonList1.SelectedValue == "5A") {
                sp_level = 1;
            } 
            else if (RadioButtonList1.SelectedValue == "4A") {
                sp_level = 2;
            }
            else if (RadioButtonList1.SelectedValue == "3A") {
                sp_level = 3;
            }
            else if (RadioButtonList1.SelectedValue == "2A") {
                sp_level = 4;
            }
            else if (RadioButtonList1.SelectedValue == "1A") {
                sp_level = 5;

            }


            string connStr = "server=121.43.119.97;user id=root;password=h666niub;persistsecurityinfo=True;database=ticket_management_system";
            MySqlConnection conn = new MySqlConnection(connStr);
            conn.Open();

            try
            {
                string insertStr = "INSERT INTO user(userName,password,identity_id) VALUES (" + username + "," + password + "," + identity + ")";
                MySqlCommand cmd = new MySqlCommand(insertStr, conn);
                cmd.ExecuteScalar();

                string insert_sp = "INSERT INTO scenicspot(scenicSpotNumber,scenicSpotName,telephone,address,scenicSpotLevel_id) VALUES (" + sp_id + "," + sp_name + "," + sp_tel + "," + sp_address + "," + sp_level + ")";
                MySqlCommand cmd2 = new MySqlCommand(insert_sp, conn);
                cmd2.ExecuteScalar();

                MessageBox.Show("注册成功！");
                conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
    }
}